package com.iterator.service.wechat.lc;

import com.iterator.bean.web.pojo.lyh.MallFeedback;
import com.iterator.bean.web.pojo.lyh.MallUserExample;
import com.iterator.bean.web.pojo.lyh.User;
import com.iterator.bean.wechat.lc.WxFeedBackBo;

import com.iterator.mapper.web.userManager.MallFeedbackMapper;
import com.iterator.mapper.web.userManager.MallUserMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WxFeedbackServiceImpl  implements WxFeedbackService{
    @Autowired
    MallFeedbackMapper feedbackMapper;
    @Autowired
    MallUserMapper userMapper;
    @Override
    public void submit(WxFeedBackBo feedBackBo) {
        String username = (String) SecurityUtils.getSubject().getPrincipal();
        MallUserExample userExample = new MallUserExample();
        userExample.createCriteria().andUsernameEqualTo(username);
        List<User> users = userMapper.selectByExample(userExample);
        User user = users.get(0);
        MallFeedback feedback = new MallFeedback(null,
                user.getId(),
                user.getUsername(),
                feedBackBo.getMobile(),
                feedBackBo.getFeedType(),
                feedBackBo.getContent(),
                0,
                feedBackBo.isHasPicture(),
                feedBackBo.isHasPicture()? feedBackBo.getPicUrls().toString():null,
                new Date(),
                new Date(),
                false);
        feedbackMapper.insert(feedback);
    }
}
